﻿#set platform related cmake definition and config
message("Load Platform Windows CMake")

set(NS_LIBS_ROOT ${DIR_LIB}/${TARGET_ABI})
set(PROJECT_LIBS_ROOT ${DIR_PROJECT_LIB}/${TARGET_ABI})

if( EXISTS "${PROJECT_SOURCE_DIR}/CMake/IDE/PlatformWindowsIDE.cmake" )
    include(${PROJECT_SOURCE_DIR}/CMake/IDE/PlatformWindowsIDE.cmake)
endif()

if( EXISTS "${PROJECT_SOURCE_DIR}/CMake/PlatformWindowsCustom.cmake" )
    include(${PROJECT_SOURCE_DIR}/CMake/PlatformWindowsCustom.cmake)
endif()

set(PLATFORM_SOURCE_MAIN ${DIR_SRC}/Platform/windows/NSMainWindows.cpp)

set(PLATFORM_SOURCE 
        #Platform/Windows
        ${PROJECT_PLATFORM_SOURCE}
        ${PROJECT_PLATFORM_CUSTOM_SOURCE}
)

if( MSVC AND EXISTS "${DIR_SRC}/Platform/windows/VersionInfo.rc" AND NOT ${NS_BUILD_ONE_LIB})
    message("Found Version RC file")

    list(APPEND PLATFORM_SOURCE_MAIN
    ${DIR_SRC}/Platform/windows/VersionInfo.rc
    )

    list(APPEND PLATFORM_SOURCE
    ${DIR_SRC}/Platform/windows/VersionInfo.rc
    )
endif()

if( ${DEBUG_PROJECT_INTERNAL} )
    set(ENGINE_LIB_NAME NSEngine)
else()
    add_library(libNSEngine SHARED IMPORTED)
    set_target_properties(libNSEngine PROPERTIES IMPORTED_IMPLIB ${NS_LIBS_ROOT}/NSEngine.lib)
    set(ENGINE_LIB_NAME libNSEngine)
endif()

list(APPEND PLATFORM_LINK_LIBS
    ${ENGINE_LIB_NAME}
    ws2_32
    winmm
    wldap32
)

if( EXISTS "${PROJECT_SOURCE_DIR}/CMake/IDE/PlatformWindowsDepIDE.cmake" )
	include(${PROJECT_SOURCE_DIR}/CMake/IDE/PlatformWindowsDepIDE.cmake)
endif()

message(">>>>>>>>> Platform Windows link libs: " ${PLATFORM_LINK_LIBS})
message(">>>>>>>>> Engine Windows link libs: " ${ENGINE_LINK_LIBS})

#ADD CUSTOM CXX FLAGS HERE
set(PLATFORM_CXX_FLAGS "${PROJECT_PLATFORM_CXX_FLAGS} ${PROJECT_PLATFORM_CUSTOM_CXX_FLAGS} /DNDEBUG /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS /std:c++17 /sdl- /MP /O2 /Zc:twoPhase- /utf-8 /Zc:wchar_t /WX-")

#ADD CUSTOM LINK FLAGS HERE
set(PLATFORM_LINK_FLAGS "${PROJECT_PLATFORM_LINK_FLAGS} ${PROJECT_PLATFORM_CUSTOM_LINK_FLAGS} /OPT:ICF /INCREMENTAL:NO /OPT:REF /NODEFAULTLIB:MSVCRTD")

message(">>>>>>>>> Platform Windows CXX flags: " ${PLATFORM_CXX_FLAGS})
message(">>>>>>>>> Platform Windows LINK flags: " ${PLATFORM_LINK_FLAGS})